package com.asialjim.wechat.spring.filter;

import com.asialjim.wechat.pojo.account.WeChatAccountHolder;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * <h1><em>ASIAL JIM JAVA DOC</em></h1><hr/>
 * <h2>CLASS DESCRIPTION <i>[ NAME: WeChatFilter ]</i></h2><strong>
 * <p> we-chat filter
 * </strong><p><p><em>Copyright &copy; Asial Jim Co., LTD</em><hr/>
 *
 * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
 * @version 1.0.0
 * @since 2021/3/16   &nbsp;&nbsp; JDK 8
 */
public class WeChatFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // empty method
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        WeChatRequestWrapper requestWrapper = new WeChatRequestWrapper((HttpServletRequest) servletRequest);
        filterChain.doFilter(requestWrapper,servletResponse);
        WeChatAccountHolder.remove();
        WeChatAccountHolder.removeToUserName();
    }

    @Override
    public void destroy() {
        // empty method
    }
}
